﻿namespace VectorPicsEditor
{
    using System;
    using System.Windows.Shapes;
    using Helpers;
    using System.Windows;

    public class ShapeWrapper
    {
        public FrameworkElement Shape { get; private set; }
        public bool WasChanged { get; set; }

        public string Name 
        {
            get 
            {
                return this.Shape.Name.Replace("_s_"," "); ;
            }
            set
            {
                this.Shape.Name = value.Replace(" ", "_s_");
            }
        }

        public event System.Windows.Input.MouseButtonEventHandler MouseSelected;
        public event System.Windows.Input.KeyboardEventHandler RemoveShape;
        public event System.Windows.Input.InputEventHandler EditText;

        public void TextBlockEdit()
        {
            if (this.Shape is System.Windows.Controls.TextBlock && this.EditText != null)
            {
                this.EditText(this.Shape, null);
            }
        }

        public void Remove(FrameworkElement shp)
        {
            if (RemoveShape != null)
                this.RemoveShape(shp, null);
        }

        public ShapeWrapper(FrameworkElement shape, string name)
        {
            this.Shape = shape;
            this.Name = name;

            this.Shape.MouseLeftButtonDown += this.ShapeMouseLeftButtonDown;
            WasChanged = false;
        }

        public void UnselectLine()
        {
            if (this.Shape is Line && this.MouseSelected != null)
                this.MouseSelected(this.Shape, null);
        }

        private void ShapeMouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            //e.Handled = true;

            if (this.MouseSelected != null)
            {
                this.MouseSelected(this, e);
            }
        }
    }
}